package 递归遍历;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: zhengtao
 * @description: 二叉树的后序遍历
 * @version: 1.0
 * @date: 2022/10/29  09:51
 */
public class Demo145 {
    List<Integer> res=new ArrayList<>();

    public List<Integer> postorderTraversal(TreeNode root) {
        if(root==null){
            return res;
        }else {
            res.add(root.val);
            postorderTraversal(root.left);
            postorderTraversal(root.right);
        }
        return res;
    }
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
